<template>
  <el-dialog :visible.sync="visible" title="延班" :close-on-click-modal=false width="550px">
    <el-form ref="delayForm" :rules="rules" :model="delayScheduleInfo" label-width="120px">
      <el-form-item label="延班日期：" prop="target">
        <el-date-picker
          v-model="delayScheduleInfo.target"
          :picker-options="pickerOptions"
          type="date"
          format="yyyy-MM-dd"
          placeholder="请选择日期"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="loading" type="primary" @click.native="changeSchedule">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { delayClassSchedule } from '@/api/class'
export default {
  data() {
    return {
      visible: false,
      loading: false,
      classId: 0,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      delayScheduleInfo: {
        classId: 0,
        target: ''
      },
      rules: {
        target: [
          { required: true, message: '请选择调整的日期', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async changeSchedule() {
      this.$refs.delayForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.delayScheduleInfo.classId = this.classId
          delayClassSchedule(this.delayScheduleInfo).then(res => {
            this.loading = false
            this.$message({
              message: '延班成功',
              type: 'success'
            })
            this.visible = false
          }).catch (err => {
            this.$notify({
              title: err.msg,
              type: 'warning',
              duration: 5000
            })
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>